package com.pg.excel.ui;/*
 * Copyright (C) 2019/8/10
 * by zhuyk
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.border.LineBorder;

/**
 * @author user
 * 边框设置
 */

public class TextBorderUtlis extends LineBorder {

    private static final long serialVersionUID = 1L;

    public TextBorderUtlis(Color color, int thickness, boolean roundedCorners) {
        super(color, thickness, roundedCorners);
    }

    @Override
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Color oldColor = g.getColor();
        Graphics2D g2 = (Graphics2D) g;
        int i;
        g2.setRenderingHints(rh);
        g2.setColor(lineColor);
        for (i = 0; i < thickness; i++) {
            if (!roundedCorners) {
                g2.drawRect(x + i, y + i, width - i - i - 1, height - i - i - 1);
            } else {
                g2.drawRoundRect(x + i, y + i, width - i - i - 1, height - i - i - 1, 5, 5);
            }
        }
        g2.setColor(oldColor);
    }

}